//
//  FBTradeHeaderView.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/31.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBTradeHeaderView.h"
@interface FBTradeHeaderView ()

@property (nonatomic,strong)UIButton *btn1;
@property (nonatomic,strong)UIButton *btn2;
@property (nonatomic,strong)UIButton *btn3;


@end


@implementation FBTradeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self createUI];
    }
    return self;
}


-(void)createUI{
    
    
    UIButton *  btn1 = [[UIButton alloc]init];
    [self addSubview:btn1];
    [btn1 setTitleColor:RGB(255,255,255) forState:UIControlStateNormal];
    [btn1 setTitle:@"购买" forState:UIControlStateNormal];
    btn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn1.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    [btn1 addTarget:self action:@selector(BugClick) forControlEvents:UIControlEventTouchUpInside];
    [btn1.layer setBorderWidth:1.0];
    btn1.layer.borderColor=ThemeColor.CGColor;
    btn1.backgroundColor=ThemeColor;
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-15);
        make.right.equalTo(self.mas_right).offset(-G_SCREENWIDTH/2.0);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    _btn1 = btn1;
    
    
    UIButton *  btn2 = [[UIButton alloc]init];
    [self addSubview:btn2];
    [btn2 setTitleColor:ThemeColor forState:UIControlStateNormal];
    [btn2 setTitle:@"出售" forState:UIControlStateNormal];
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn2.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    [btn2 addTarget:self action:@selector(SaleClick) forControlEvents:UIControlEventTouchUpInside];
    [btn2.layer setBorderWidth:1.0];
    btn2.layer.borderColor=ThemeColor.CGColor;
    btn2.backgroundColor=[UIColor whiteColor];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-15);
        make.left.equalTo(self.mas_left).offset(G_SCREENWIDTH/2.0);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    _btn2=btn2;
    
    UIButton *  btn3 = [[UIButton alloc]init];
    [self addSubview:btn3];
    btn3.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [btn3 addTarget:self action:@selector(AllOrderClick) forControlEvents:UIControlEventTouchUpInside];
//    [btn3.layer setBorderWidth:1.0];
//    btn3.layer.borderColor=ThemeColor.CGColor;
    btn3.backgroundColor=MC_TEST_COLOR;
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    _btn3=btn3;
    
    
    
    UILabel * lab = [[UILabel alloc]init];
    [self setLab:lab withColor:RGB(110, 110, 110) andFont:12 andText:@"全部订单" andTextAlignment:NSTextAlignmentRight];
    [btn3 addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btn3.mas_centerY).offset(0);
        make.right.equalTo(btn3.mas_right).offset(-20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
    
    
    _num = [[UILabel alloc]init];
    [self setLab:_num withColor:RGB(255, 255, 255) andFont:10 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    [btn3 addSubview:_num];
    [_num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btn3.mas_centerY).offset(-10);
        make.left.equalTo(lab.mas_right).offset(-5);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    _num.layer.cornerRadius = 10;
    _num.clipsToBounds=YES;
    _num.hidden=YES;
    _num.backgroundColor = [UIColor redColor];
    
    
    UIImageView * weixin = [[UIImageView alloc]init];
    [btn3 addSubview:weixin];
    weixin.image = [UIImage imageNamed:@"更多btn"];
    [weixin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(btn3.mas_right).offset(0);
        make.centerY.equalTo(btn3.mas_centerY).offset(0);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(15);
        
    }];
    
    
}
-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}

+(CGFloat)computeHeight:(id)info{
    
    return 30+TopBackButtonHeight+20;
    
}

-(void)BugClick{
    
    _btn1.backgroundColor=ThemeColor;
    [_btn1 setTitleColor:RGB(255,255,255) forState:UIControlStateNormal];

    _Type = FBTradeHeaderType_Bug;
    
    _btn2.backgroundColor=[UIColor whiteColor];
    [_btn2 setTitleColor:ThemeColor forState:UIControlStateNormal];

    if (self.bugBlock) {
        self.bugBlock();
    }
}

-(void)SaleClick{
    
    _btn1.backgroundColor=[UIColor whiteColor];
    [_btn1 setTitleColor:ThemeColor forState:UIControlStateNormal];
    
    
    _btn2.backgroundColor=ThemeColor;
    [_btn2 setTitleColor:RGB(255,255,255) forState:UIControlStateNormal];

    _Type = FBTradeHeaderType_Sale;
    
    if (self.saleBlock) {
        self.saleBlock();
    }
}

#pragma mark-全部订单
-(void)AllOrderClick{
    
    if (self.allOrderBlock) {
        self.allOrderBlock();
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
